﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using SCS.Common.Models;

namespace SCS.DAL
{
    public class TeacherRepository : Repository<Teacher>, ITeacherRepository
    {
        public TeacherRepository(SCSContext _context)
            : base(_context)
        { }
        /// <summary>
        /// Count all for Teacher
        /// </summary>
        /// <returns>total number Teacher</returns>
        public int GetCount()
        {
            return DBSet.Count();
        }

        /// <summary>
        /// Count search result
        /// </summary>
        /// <param name="searchString">search text</param>
        /// <returns>total number search result</returns>
        public int GetSearchCount(string searchString)
        {
            return DBSet.Where(s => s.teacherName.Contains(searchString)).Count();
        }

        /// <summary>
        /// Get teacher for paging
        /// </summary>
        /// <param name="pageNumber">Number Page</param>
        /// <param name="pageSize">Size of Page</param>
        /// <returns>List Teacher</returns>
        public IEnumerable<Teacher> GetTeacherPaging(int pageNumber, int pageSize)
        {
            return DBSet.OrderBy(x => x.teacherID)
          .Skip((pageNumber - 1) * pageSize)
          .Take(pageSize)
          .ToList();
        }

        /// <summary>
        /// Search Result of Teacher
        /// </summary>
        /// <param name="pageNumber">Number Page</param>
        /// <param name="pageSize">Size of Page</param>
        /// <param name="searchString">search text</param>
        /// <returns>List Teacher</returns>
        public IEnumerable<Teacher> SearchTeacherPaging(int pageNumber, int pageSize, string searchString)
        {
            return DBSet.Where(s => s.teacherName.Contains(searchString)).OrderBy(x => x.teacherID)
         .Skip((pageNumber - 1) * pageSize)
         .Take(pageSize)
         .ToList();
        }
    }
}